// store.ts
import { defineStore } from 'pinia'
import { reactive, computed, ref, watchEffect } from 'vue'

export const useGlobalUploadDialogStore = defineStore('globalUploadDialog', () => {
  const show = ref(false)

  const uploadInfo = ref<any>({})

  const showDialog = () => {
    show.value = true
    console.log(show.value, 'show.value')
  }

  const hideDialog = () => {
    show.value = false
  }

  const setUploadInfo = (data: any) => {
    uploadInfo.value = reverseObj(data)
    console.log(uploadInfo.value, 'uploadInfo.valueuploadInfo.value')
  }

  const reverseObj = (obj: any) => {
    const sortedObj: any = {}
    const keys = Object.keys(obj).reverse()

    keys.forEach((key) => {
      sortedObj[key] = obj[key]
    })
    return sortedObj
  }

  return {
    show,
    uploadInfo,
    setUploadInfo,
    showDialog,
    hideDialog
  }
})
